package com.shiro.entity;

import java.util.Date;
import java.util.Objects;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import com.fasterxml.jackson.annotation.JsonFormat;

@Document
public abstract class IdEntity {

	@Id
	protected String id;
	private String creator;
	private Date createDate;
	private String modifier;
	private Date modifyDate;
	private String desc;
	private boolean delflag = false;

	public IdEntity() {
		createDate = new Date();
		modifyDate = new Date();
	}

	public String getId() {
		return id;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	// 设定JSON序列化时的日期格式
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	// 设定JSON序列化时的日期格式
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public boolean getDelflag() {
		return delflag;
	}

	public void setDelflag(boolean delflag) {
		this.delflag = delflag;
	}
	
	@Override
	public int hashCode()
	{
		if ("".equals(getId())){
			return super.hashCode();
		}
		return Objects.hashCode(this.getId());
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		
		if (obj == null) {
			return false;
		}

		if ( (obj.getClass() != getClass()) ) {
			return false;
		}

		IdEntity idEntity = (IdEntity) obj;

		return getId().equals(idEntity.getId());
	}

	@Override
	public String toString(){
		return this.getId();
	}
}